<template lang="pug">
.header
  .header-title
  .header-user
    el-popover(
      popper-class="header-popover"
      placement="top-end"
      width="120"
      trigger="hover"
      :visible-arrow="false"
    )
      .service
        .service-wrapper
          router-link.service-item(:to="{ name: 'info' }")
            .iconfont.icon-company
            .service-item-bd 企业信息
          .service-item(@click="logout")
            .iconfont.icon-loginout
            .service-item-bd 退出系统
      .header-user-handle(slot="reference")
        .header-handle-item {{userInfo.companyName}}
        .header-handle-head(:style="userInfo.headImage | filterUrl")
    //- .header-user-system {{userInfo.system_type}}
    //- .header-user-name {{titleType === 'all' ? userInfo.suppliers_name : userInfo.short_name}}
    //- el-popover(
        popper-class="header-popover"
        placement="top"
        width="214"
        trigger="hover"
        :visible-arrow="false"
      )
        .login-info
          .login-info-container
            .login-info-title 当前帐号
            .login-info-detail
              .login-info-account {{userInfo.user_name}}
              .logo-info-userType {{userInfo.user_type}}
          .login-info-section(@click="toggleTitle")
            .toggle-title
              p 切换显示为：{{titleType === 'all' ? '企业简称' : '企业全称'}}
              i.icon-transform
          //- router-link.login-info-section(:to="{name: 'basicInfo'}") 企业信息
          .login-handle(@click="logout")
            .login-handle-text 退出登录
            .login-handle-icon.icon-power
        .header-handle(slot="reference")
          i.icon-user
</template>

<script>
import { mapState, mapActions } from 'vuex'
import { logout } from 'api'
import { delCookie, getCookie } from 'utils/cookie'
export default {
  name: 'appHeader',
  data () {
    return {
      titleType: 'all'
    }
  },
  methods: {
    ...mapActions([
      'changeUserInfo'
    ]),
    async logout () {
      try {
        await this.$axios.post(logout)
        this.changeUserInfo({})
        delCookie('COMPANY_NAME')
        delCookie('CNPASS_PLAT')
        delCookie('HEADIMG')
        delCookie('CNPASS')
        this.$message({ message: '退出登录', type: 'success' })
        this.$router.replace({ name: 'login' })
      } catch ({ msg }) {
        this.$message.error(msg)
      }
    },
    // async getSpByDirectory () {
    //   try {
    //     const { data } = await this.$axios.get(getSpByDirectory)
    //     this.changeSuppliers(data)
    //   } catch (err) {
    //     this.$message.error(err.msg)
    //   }
    // },
    resetPswd () {
      this.$router.push({name: 'password'})
    }
  },
  computed: {
    title () {
      return this.$route.meta.title
    },
    ...mapState({
      lowerSidebarShow: state => state.ui.lowerSidebar.show,
      userInfo: state => state.user.user
    })
  }
}
</script>

<style lang="scss">
.header-popover {
  &.el-popover {
    padding: 0 !important;
  }
}
</style>

<style lang="scss" scoped>
.header {
  position: fixed;
  top: 0;
  width: calc(100% - 208px);
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 24px;
  background: #FFFFFF;
  box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.05);
}
.header-title {
  font-size: 16px;
  font-weight: 600;
  color: #626262;
  line-height: 22px;
}
.header-handle {
  position: relative;
  .icon-user {
    cursor: pointer;
    font-size: 24px;
    color: #999;
  }
}
.login-info-title {
  font-size: 13px;
  font-weight: 400;
  color: #CCCCCC;
  line-height: 18px;
}
.login-info-container {
  padding: 10px;
}
.login-info-detail {
  display: flex;
  align-items: center;
  margin-top: 10px;
  .login-info-account {
    font-size: 14px;
    font-weight: 600;
    color: #000000;
    line-height: 20px;
  }
  .logo-info-userType {
    padding: 0 5px;
    height: 20px;
    line-height: 20px;
    border-radius: 2px;
    border: 1px solid #FF5500;
    margin-left: 5px;
    color: #FF5500;
    cursor: pointer;
  }
  .login-info-tag {
    margin-left: 5px;
    padding: 2px 5px;
    background: #FFF6F2;
    border-radius: 2px;
    border: 1px solid #FF5500;
    font-size: 12px;
    font-weight: 400;
    color: #FF6213;
    line-height: 17px;
  }
}
.login-info-section {
  padding: 0 14px;
  height: 40px;
  border-top: 1px solid #D9D9D9;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.toggle-title {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 400;
  color: #333333;
  line-height: 18px;
  .icon-transform {
    font-size: 12px;
  }
}
.login-handle {
  background: #F4F4F4;
  box-shadow: 0px -1px 0px 0px #D9D9D9;
  border-radius: 0px 0px 2px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  cursor: pointer;
  .login-handle-text {
    font-size: 13px;
    font-weight: 400;
    color: #000000;
    line-height: 18px;
  }
}
.header-user {
  display: flex;
  align-items: center;
}
.header-user-system {
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 400;
  color: #FF4200;
  line-height: 17px;
  border: 1px solid #FF4200;
  border-radius: 10px;
  margin-right: 10px;
}
.header-user-name {
  margin-right: 10px;
  font-size: 13px;
  font-weight: 400;
  color: #333333;
  line-height: 18px;
}
.header-user-handle {
  display: flex;
  align-items: center;
  margin-right: 12px;
  .header-handle-item {
    cursor: pointer;
    margin-left: 20px;
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    line-height: 20px;
  }
}
.header-handle-head {
  width: 24px;
  height: 24px;
  margin-left: 16px;
  border-radius: 50%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
.service {
  height: 120px;
  display: flex;
  align-items: center;
}
.icon-phone {
  font-size: 20px;
  vertical-align: middle;
}
.service-wrapper {
  height: 100%;
  width: 100%;
}
.service-item {
  width: 100%;
  padding: 5px 0;
  margin: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #707070;
  cursor: pointer;
  &:hover {
    color: #363636;
  }
  .iconfont {
    font-size: 14px;
    margin-right: 12px;
  }
  .service-item-bd {
    font-size: 14px;
    line-height: 1;
  }
}
</style>
